package model.commands;

import java.awt.Robot;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;

public abstract class AbstractCommand implements Command {
	protected Robot robot;
	protected PropertyChangeSupport propertyChangeSupport;
	protected boolean pause = false;
	protected boolean stop = false;
	
	public AbstractCommand(){
		propertyChangeSupport = new PropertyChangeSupport(this);
	}
	
	@Override
	public void setRobot(Robot robot) {
		this.robot = robot;
	}
	
	@Override
	public void addEventListener(String eventName, PropertyChangeListener listener){
		propertyChangeSupport.addPropertyChangeListener(eventName, listener);
	}
	
	@Override
	public synchronized void stop() {
		stop = true;
		pause = false;
		notifyAll();
	}
	
	@Override
	public synchronized void pause() {
		pause = true;
	}
	
	@Override
	public synchronized void resume() {
		resetRunningVariables();
		notifyAll();
	}
	
	@Override
	public void resetRunningVariables(){
		stop = false;
		pause = false;
	}
}
